Skip to content

fix(api): remove duplicate /api/traces endpoint that broke React UI#9427

Merged
mudler merged 2 commits intomudler:masterfrom
pjbrzozowski:fix/api-traces-duplicate-endpoint
Apr 20, 2026
Merged

fix(api): remove duplicate /api/traces endpoint that broke React UI#9427
mudler merged 2 commits intomudler:masterfrom
pjbrzozowski:fix/api-traces-duplicate-endpoint

Conversation

@pjbrzozowski
Copy link
Copy Markdown
Contributor

@pjbrzozowski pjbrzozowski commented Apr 19, 2026

Problem

The API Traces tab in /app/traces always showed (0) traces — no API request/response pairs were ever displayed, even though Backend Traces worked fine.

Root Cause

The /api/traces endpoint was registered in two places:

  1. core/http/routes/localai.go — returns a flat []APIExchange array ✅
  2. core/http/routes/ui_api.go — returns a wrapped {"traces": [...]} object ❌

Echo matched the ui_api.go handler. The React UI (Traces.jsx) does Array.isArray(apiData) ? apiData : [], which always evaluated to [] because the response was an object, not an array. The legacy Alpine.js UI (traces.html) also assigns the response directly and expected an array.

Both bugs were introduced in commit 99b5c5f ("feat(api): Allow tracing of requests and responses #7609").

Fix

  • Remove the duplicate /api/traces and /api/traces/clear endpoints from ui_api.go, keeping only the correct flat-array versions in localai.go
  • Use mime.ParseMediaType() for the Content-Type check in the trace middleware, so requests with parameters (e.g. application/json; charset=utf-8) are still traced

Testing

Built and deployed to a test instance. Verified:

  • GET /api/traces returns a flat JSON array
  • API Traces tab shows traced requests with correct method, path, status, and duration
  • Clear button works

@pjbrzozowski pjbrzozowski force-pushed the fix/api-traces-duplicate-endpoint branch from 621ac83 to 65309c9 Compare April 19, 2026 15:20
The API Traces tab in /app/traces always showed (0) traces despite requests
being recorded.

The /api/traces endpoint was registered in both localai.go and ui_api.go.
The ui_api.go version wrapped the response as {"traces": [...]} instead of
the flat []APIExchange array that both the React UI (Traces.jsx) and the
legacy Alpine.js UI (traces.html) expect. Because Echo matched the ui_api.go
handler, Array.isArray(apiData) always returned false, making the API Traces
tab permanently empty.

Remove the duplicate endpoints from ui_api.go so only the correct flat-array
version in localai.go is served.

Also use mime.ParseMediaType for the Content-Type check in the trace
middleware so requests with parameters (e.g. application/json; charset=utf-8)
are still traced.

Signed-off-by: Pawel Brzozowski <paul@ontux.net>
@pjbrzozowski pjbrzozowski force-pushed the fix/api-traces-duplicate-endpoint branch from 65309c9 to f55a4b2 Compare April 19, 2026 15:33
@mudler mudler requested a review from richiejp April 19, 2026 15:55
Copy link
Copy Markdown
Collaborator

@richiejp richiejp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly enough, this did work despite the problem always being there and probably it stopped working after a refactor.

The solution looks about right, thanks!

@pjbrzozowski
Copy link
Copy Markdown
Contributor Author

Oddly enough, this did work despite the problem always being there and probably it stopped working after a refactor.

The solution looks about right, thanks!

Thanks for the approval! I think I stopped pending checks by merging the master into this branch.

@mudler mudler merged commit ecf85fd into mudler:master Apr 20, 2026
1 check passed
@pjbrzozowski pjbrzozowski deleted the fix/api-traces-duplicate-endpoint branch April 20, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants